<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('comment-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<?php //echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?>
<!--div class="search-form" style="display: none">
< ?php 
	$this->renderPartial('_search', array(
		'model' => $model,
	)); 
?>
</div><!-- search-form -->

<div class="widget-box dataTables_wrapper ">
	<?php $form=$this->beginWidget('CActiveForm', array(
		'id'=>'comment-form',
		'action' => Yii::app()->createUrl('/articles/ManageComments/admin', array('article_id'=>$_GET['article_id'])),
		'htmlOptions'=>array(
				'class'=>'jform',
		),
	)); ?>
		
		<?php 
		//$this->widget('zii.widgets.grid.CGridView', array(
		$this->widget('ext.selgridview.SelGridView', array(
			'id' => 'comment-grid',
			'htmlOptions'	=> array('class' => 'widget-content nopadding grid-view'),
			'itemsCssClass'	=>	'table table-bordered table-striped table-hover table-border-bottom',
			'dataProvider' => $model->search(),
			'template' => count($model->search()->getData())==0?'{items}':'{items}<div class="fg-toolbar widget-content"><a href="#" class="btn" onclick="return actionDelete();">Delete</a>{pager}{summary}</div>',
			'selectableRows'=>count($model->search()->getData()),
			//'filter' => $model,
			'columns' => array(
				array(
					'class' => 'CCheckBoxColumn',
					'htmlOptions' => array('class'=>'jform'),
					'headerHtmlOptions' => array('class' => 'jform jlb_checkbox_check_all jlb_checkbox_check_all_disable'),
					'header' => '<input type="checkbox" class="select-on-check-all"/>',
					'value' => '$data->primaryKey',
				),
				'id',
				array(
					'name' 	=> 'content',
					'type'	=> 'raw',
					'value' => '$data->limit_text($data->content, 50)',
				),
				array(
					'header'=>'Authors',
					'name' => 'username',
					'value' => '$data->getAuthorName($data->user_id)',
				),
				//'created',
				array(
					'name'=>'created',
					'type'=>'datetime',
					'filter'=>false,
				),
				array(
					'name' => 'status',
					'value' => '($data->status === 0) ? Yii::t(\'app\', \'No\') : Yii::t(\'app\', \'Yes\')',
					'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),
					),
				array(
					'class' => 'CButtonColumn',
				),
			),
		)); ?>
		
	<?php $this->endWidget(); ?>
</div>
<script type="text/javascript">
	function actionDelete()
	{
		if ($("input:checkbox[name='comment-grid_c0[]']:checked").length == 0) {
			alert('<?php echo 'Please select at least one item to remove.'; ?>');
			return false;
		}
		if (confirm('<?php echo 'Are you sure you want to delete?'; ?>')) $('#comment-form').submit();
		return false;
	}
</script>